home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS05.ADF / printer / printer.c < prev    next >
C/C++ Source or Header  |  1986-01-15  |  3KB  |  95 lines

  1.  
  2. /* printer.c - program to do a raster dump to whatever printer is specified
  3.  *        by Preferences, of the Workbench Screen.  
  4.  *
  5.  * Author:  Rob Peck, 12/1/85
  6.  *
  7.  * This code may be freely utilized to develop programs for the Amiga */
  8.  */
  9.  
  10.  
  11. #include "exec/types.h"
  12. #include "intuition/intuition.h"
  13. #include "devices/printer.h"
  14. #define INTUITION_WONT_OPEN 1000
  15.  
  16. union printerIO {
  17.        struct IOStdReq ios;
  18.        struct IODRPReq iodrp;
  19.        struct IOPrtCmdReq iopc;
  20.        };
  21.  
  22. union printerIO *request;     /* a pointer to a request block */
  23. extern int DumpRPort();
  24. extern struct IORequest *CreateExtIO();
  25. extern struct Window *OpenWindow();
  26. extern struct Port *CreatePort();
  27. struct IntuitionBase *IntuitionBase;
  28.  
  29. struct NewWindow nw = {
  30.         0, 0, 100, 40, 0, 1, 0, 0, NULL, NULL, NULL, NULL, NULL,
  31.         0, 0, 0, 0, WBENCHSCREEN
  32.         };
  33.          
  34. main()
  35. {
  36.         struct Window *w;
  37.         struct Screen *screen;
  38.         struct RastPort *rp;
  39.         struct ViewPort *vp;
  40.         struct ColorMap *cm;
  41.      union printerIO sizeDummy;
  42.         int modes,width,height,error;
  43.         struct Port *printerPort;      /* at which to receive reply */
  44.         IntuitionBase = (struct IntuitionBase *)OpenLibrary(
  45.                               "intuition.library", 0);
  46.         if (IntuitionBase == NULL) exit(INTUITION_WONT_OPEN);
  47.  
  48.         w = OpenWindow(&nw);
  49.         if(w == NULL) goto cleanup1;
  50.         screen = w->WScreen;    /* get screen address from window */
  51.         CloseWindow(w);         /* once have screen address, no
  52.                                  * more need for window, close it.
  53.                                  */
  54.         vp = &screen->ViewPort; /* get screen's ViewPort, from
  55.                                  * which the colormap will be gotten */
  56.         rp = &screen->RastPort; /* get screen's RastPort, which
  57.                                  * is what gets dumped to printer */
  58.         
  59.         cm = vp->ColorMap;      /* retrieve pointer to colormap for
  60.                                  * the printer dump */
  61.         modes = vp->Modes;      /* retrieve the modes variable */
  62.         width = vp->DWidth;     /* retrieve width to print */
  63.         height = vp->DHeight;   /* retrieve height to print */
  64.  
  65.         printerPort = CreatePort("my.print.port",0);
  66.         request =  (union printerIO *)CreateExtIO(printerPort,
  67.                                         sizeof(sizeDummy));
  68.  
  69.         error = OpenPrinter(request);
  70.         if(error != 0) goto cleanup2;
  71.  
  72.      Delay(300);    /* 300/60 = 6 seconds delay before it starts */
  73.         error = DumpRPort(
  74.                         request,/* pointer to initialized request */
  75.                         rp,     /* rastport pointer */
  76.                         cm,     /* color map pointer */
  77.                         modes,  /* low, high res, etc (display modes)*/
  78.                         0, 0,   /* x and y offsets into rastport */
  79.                         width,height, /* source size */
  80.                         width,(height * 2), /* dest rows, columns */
  81.                         SPECIAL_FULLROWS 
  82.                | SPECIAL_FULLCOLS
  83.                | SPECIAL_ASPECT /* io Special value, says print
  84.                                  * as pixels only, direct copy */
  85.                         );
  86.         ClosePrinter(request);
  87. cleanup2:
  88.         DeleteExtIO(request, sizeof(sizeDummy));
  89.         DeletePort(printerPort);
  90. cleanup1:
  91.         CloseLibrary(IntuitionBase);
  92.         
  93. }               /* end of demo screen dump */
  94.  
  95.